package controle;
import java.io.File;
import java.io.FileReader;

import br.ufrj.nce.multiplus.fuzzylab.io.IOMatLab;
import br.ufrj.nce.multiplus.fuzzylab.kernel.SistemaFuzzy;

public class Fuzzy {
	private static SistemaFuzzy sistemaFuzzy;
	
	public static double avalia(double distancia, double angulo, double y) {
	    double []entradas;
	    double []saidas;
	    int numPontos = 10;
	    
	    entradas = new double[3];
	    entradas[0] = distancia;
	    entradas[1] = angulo;
	    entradas[2] = y;

		try {
			if (sistemaFuzzy == null)
				sistemaFuzzy = IOMatLab.carregaSistemaFuzzy(new FileReader(new File("./robo.fis")));
			
			saidas = sistemaFuzzy.infereSistemaFuzzy(entradas, numPontos);
			
			return saidas[0];
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0; 
	}
	
}
